package com.zit.dao;

import java.io.Serializable;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.List;

import org.hibernate.Session;


public class BaseDAO {

	public List findAll(Class<?> clazz, Session s) {
		return s.createCriteria(clazz).list();
	}

	public Object findById(Class<?> clazz, Serializable id, Session s) {
		return s.get(clazz, id);
	}

	public void delete(Object obj, Session s) throws SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException, InvocationTargetException {
		Class c = obj.getClass();
		Method m = c.getMethod("setIsDelete",Integer.class);
		m.invoke(obj,1);
		this.update(obj, s);
		
	}

	public void update(Object obj, Session s) {
		s.update(obj);
	}

	public void save(Object obj, Session s) {
		s.save(obj);
	}

}
